#!/bin/sh
# witchcraft.sh - Main entry point for the witchlinux project
# Revival version - 2025

# Determine script location to allow proper relative imports
SCRIPT_DIR="$(dirname "$(readlink -f "$0")")"
WITCH_ROOT="$(dirname "$SCRIPT_DIR")"

# Source shared libraries
. "$WITCH_ROOT/lib/common.sh"
. "$WITCH_ROOT/lib/ui.sh"

# ASCII art witch hat function
#witcheshat() {
#    echo "
#                     _;*(=lll>*^-
#                  ;{KRRRRQqkeyuoAG2X2>,
#                *GRRRRR\$!`        \`\`
#              \`yRRNNRRQ,
#             \`XRRNMNRQH
#             xRRNNBNRRQ\\
#            ,RRRNNBNNRQQl
#             sRRRNNBNNRRQg*
#            GgQRRNNNNRRQg2:_
#      ,^\\toGRNNNNB@@NNNNNRRRQP1r\\\".
#:\\zoGQRRRRRRNNNNNBMROPS%yyF2oyuuuuv*\\\"\`
#  \`,:^!*\\\\\\\\r*!;:.
#"
#}

# ASCII art witch hat function
witcheshat() {
    cat << 'WITCHART'

                     _;*(=lll>*^-
                  ;{KRRRRQqkeyuoAG2X2>,
                *GRRRRR$!`        ``
              `yRRNNRRQ,
             `XRRNMNRQH
             xRRNNBNRRQ\
            ,RRRNNBNNRQQl
             sRRRNNBNNRRQg*
            GgQRRNNNNRRQg2:_
      ,^\toGRNNNNB@@NNNNNRRRQP1r\".
:\zoGQRRRRRRNNNNNBMROPS%yyF2oyuuuuv*\"`
  `,:^!*\\\\r*!;:.

WITCHART
}

# Show welcome banner and version info
show_welcome() {
    clear
    witcheshat
    echo "=========================================="
    echo "           WitchCraft Installer          "
    echo "  Universal Linux Installation & Config  "
    echo "=========================================="
    echo "Version: 0.1.0-revival"
    echo ""
    echo "Revival of the witchlinux project - bringing"
    echo "universal installation magic back to life!"
    echo ""
}

# Main menu - entry point for all functions
main_menu() {
    show_welcome
    
    echo "What would you like to do today?"
    echo ""
    echo "1) Install a new system"
    echo "2) Configure existing system" 
    echo "3) Create custom image (ISO/tarball)"
    echo "4) Exit"
    echo ""
    
    printf "Enter your choice [1-4]: "
    read -r choice
    
    case "$choice" in
        1) "$WITCH_ROOT/installers/select_distro.sh" ;;
        2) "$WITCH_ROOT/config/configure.sh" ;;
        3) "$WITCH_ROOT/image/create_image.sh" ;;
        4) echo "Exiting witchcraft.sh - may your system be ever 
stable!"; exit 0 ;;
        *) echo "Invalid option. Please try again."; sleep 2; main_menu 
;;
    esac
}

# Export WITCH_ROOT so it's available to all subscripts
export WITCH_ROOT

# Check for root privileges
#if [ "$(id -u)" -ne 0 ]; then
#    echo "Error: This script must be run as root."
#    echo "Please try again with sudo or as the root user."
#    exit 1
#fi

# Start the main program
main_menu
